#####S3 - Generates summary statistics on demographics of survey

##S3A - generates summary statistics on gender
#create table of gender
S3A<-svytable(~gender,nd)

#rename values to substantive, rather than binary names
names(S3A)<-c("Male","Female")

#round to whole numbers from weighting 
S3A<-round(S3A)

#write out results
write.csv(S3A,"../Supplementary Results/TableS3A.csv")

##S3B - Generates summary statistics on race/ethnicity

#generate table of values for race
S3B<-svytable(~racethnicity,nd)

#replace codes with substantive values
names(S3B)<-c("White, Non-Hispanic","Black, Non-Hispanic","Other, Non-Hispanic","Hispanic","Multiple", "AAPI")

#round to whole numbers
S3B<-round(S3B)

#write out results
write.csv(S3B,"../Supplementary Results/TableS3B.csv")

#S3C - write out summary statistics on income
#create table
S3C<-svytable(~income9,nd)

#replace codes with substantive labels
names(S3C)<-c("Under 10K","10-20K","20-30K","30-40K","40-50K","50-75K","75-100K","100-150K",">150K")

#round to whole numbers
S3C<-round(S3C)

#write out results
write.csv(S3C,"../Supplementary Results/TableS3C.csv")        

##S3D - generate summary statistics on education
#create table by category of education
S3D<-svytable(~educ5,nd)

#replace codes with substantive labels
names(S3D)<-c("Less than HS","HS Graduate","Some College","Bachelors Degree", "Post-Grad Degree")

#round to whole numbers
S3D<-round(S3D)

#write out results
write.csv(S3D,"../Supplementary Results/TableS3D.csv")

##S3E - generate summary statistics by party id

#create table
S3E<-svytable(~partyid5,nd)

#replace codes with substantive labels
names(S3E)<-c("Unknown","Democrat","Lean Democrat","Independent","Lean Republican","Republican")

#round to whole numbers
S3E<-round(S3E)

#write out results
write.csv(S3E,"../Supplementary Results/TableS3E.csv")

